import { defineStore } from 'pinia'
import { store } from '../index'

export const useLockStore = defineStore('lock', {
  state: () => ({
    lockInfo: {
      // isLock: false,
      // password: ''
    }
  }),

  getters: {
    getLockInfo(state) {
      return state.lockInfo
    }
  },

  actions: {
    setLockInfo(lockInfo) {
      this.lockInfo = lockInfo
    },
    resetLockInfo() {
      this.lockInfo = {}
    },
    unLock(password) {
      if (this.lockInfo?.password === password) {
        this.resetLockInfo()
        return true
      } else {
        return false
      }
    }
  },

  persist: true
})

export const useLockStoreWithOut = () => useLockStore(store)
